<template>
  <div>
    <div style="display: flex;">
      <el-button @click="drawer = true; listobj.parent_id = 1" type="primary" style="margin-bottom: 20px;">
        添加商品
      </el-button>
      <el-button @click="" type="primary" style="margin-bottom: 20px;">
        添加商品详情
      </el-button>
      <div class="block">
        <span class="demonstration" style="margin-left: 100px;">添加到该商品下/列表对应商品(添加商品必选！):</span>
        <el-cascader v-model="value" :options="options" :props="{ expandTrigger: 'hover' }" @change="handleChange">
        </el-cascader>
      </div>
    </div>

    <el-drawer title="我是标题" :visible.sync="drawer" :with-header="false">
      <div class="boxs">

        <div><span>isHot布尔值</span> <el-input v-model="listobj.ishot"></el-input><span>isNewPro布尔值</span> <el-input
            v-model="listobj.isnewpro"></el-input></div>
        <div><span>isTehui布尔值</span> <el-input v-model="listobj.istehui"></el-input><span>proName菜/商品名</span> <el-input
            v-model="listobj.proname"></el-input></div>
        <div><span>unit货品单位</span> <el-input v-model="listobj.unit"></el-input><span>oldPrice原价</span> <el-input
            v-model="listobj.oldprice"></el-input></div>
        <div><span>newPrice现价</span> <el-input v-model="listobj.newprice"></el-input><span>GetTime模糊送达日期</span> <el-input
            v-model="listobj.gettime"></el-input></div>
        <div><span>isCutDownMoney布尔值</span> <el-input
            v-model="listobj.iscutdownmoney"></el-input><span>activity两件七折</span> <el-input
            v-model="listobj.activity"></el-input></div>
        <div><span>img链接</span> <el-input v-model="listobj.img"></el-input><span>shopCarCount购物车数量</span> <el-input
            v-model="listobj.shopcarcount"></el-input></div>
        <div><span>isProcure是否采购中</span> <el-input v-model="listobj.isprocure"></el-input><span>assess该商品用户评价</span>
          <el-input v-model="listobj.assess"></el-input>
        </div>
        <div><span>assessCount该商品用户评价总数</span> <el-input v-model="listobj.assesscount"></el-input><span>stock库存</span>
          <el-input v-model="listobj.stock"></el-input>
        </div>
        <div><span>desc描述</span> <el-input v-model="listobj.desc"></el-input><span>brand商品品牌</span> <el-input
            v-model="listobj.brand"></el-input></div>
        <div><span>specs规格</span> <el-input v-model="listobj.specs"></el-input><span>producer产地</span> <el-input
            v-model="listobj.producer"></el-input></div>
        <div><span>weight重量</span> <el-input v-model="listobj.weight"></el-input><span>expDate保质期</span> <el-input
            v-model="listobj.expdate"></el-input></div>
        <div><span>proInfoImg商品描述图片</span> <el-input v-model="listobj.proinfoimg"></el-input></div>
      </div>

      <div style="text-align: center;">
        <el-button @click="ad_pro">发布</el-button>
      </div>
    </el-drawer>

    <el-drawer title="我是标题" :visible.sync="drawers" :with-header="false">

     
      <div><span>isHot布尔值</span> <el-input v-model="listobj.ishot"></el-input><span>isNewPro布尔值</span> <el-input
            v-model="listobj.isnewpro"></el-input></div>
        <div><span>isTehui布尔值</span> <el-input v-model="listobj.istehui"></el-input><span>proName菜/商品名</span> <el-input
            v-model="listobj.proname"></el-input></div>
        <div><span>unit货品单位</span> <el-input v-model="listobj.unit"></el-input><span>oldPrice原价</span> <el-input
            v-model="listobj.oldprice"></el-input></div>
        <div><span>newPrice现价</span> <el-input v-model="listobj.newprice"></el-input><span>GetTime模糊送达日期</span> <el-input
            v-model="listobj.gettime"></el-input></div>
        <div><span>isCutDownMoney布尔值</span> <el-input
            v-model="listobj.iscutdownmoney"></el-input><span>activity两件七折</span> <el-input
            v-model="listobj.activity"></el-input></div>
        <div><span>img链接</span> <el-input v-model="listobj.img"></el-input><span>shopCarCount购物车数量</span> <el-input
            v-model="listobj.shopcarcount"></el-input></div>
        <div><span>isProcure是否采购中</span> <el-input v-model="listobj.isprocure"></el-input><span>assess该商品用户评价</span>
          <el-input v-model="listobj.assess"></el-input>
        </div>
        <div><span>assessCount该商品用户评价总数</span> <el-input v-model="listobj.assesscount"></el-input><span>stock库存</span>
          <el-input v-model="listobj.stock"></el-input>
        </div>
        <div><span>desc描述</span> <el-input v-model="listobj.desc"></el-input><span>brand商品品牌</span> <el-input
            v-model="listobj.brand"></el-input></div>
        <div><span>specs规格</span> <el-input v-model="listobj.specs"></el-input><span>producer产地</span> <el-input
            v-model="listobj.producer"></el-input></div>
        <div><span>weight重量</span> <el-input v-model="listobj.weight"></el-input><span>expDate保质期</span> <el-input
            v-model="listobj.expdate"></el-input></div>
        <div><span>proInfoImg商品描述图片</span> <el-input v-model="listobj.proinfoimg"></el-input></div>
        <div style="text-align: center;">
        <el-button @click="axsf">发布</el-button>
      </div>
    </el-drawer>
    <Table :tableData="tableData" :limit="limit" :total="total" :page="page" @leftedit="leftedit" :obnus="obnus">
    </Table>
    <el-pagination background layout="prev, pager, next" :total="total" :current-page.sync="page" :page-size.sync="limit"
      @current-change="handleCurrentchange">
    </el-pagination>
  </div>
</template>

<script>
import Table from './table.vue'
import User from '../../api/product'
// import addPro from '@/api/addpro'
import axios from 'axios'
export default {
  name: 'list',
  components: {
    Table
  },
  data() {
    return {
      value: [],
      options: [
        {
          value: 1,
          label: '精品果蔬',
          children:
            [
              {
                value: 11,
                label: '精品蔬菜',

              },
              {
                value: 12,
                label: '时令水果',
              },
              {
                value: 13,
                label: '热带水果',
              }
            ]
        },
        {
          value: 2,
          label: '海鲜水产',
          children:
            [
              {
                value: 17,
                label: '虾类',

              },
              {
                value: 19,
                label: '鱼类',
              },

            ]
        },
        {
          value: 3,
          label: '熟食冻品',
          children:
            [
              {
                value: 23,
                label: '冰淇凌',

              },
              {
                value: 24,
                label: '速冻主食',
              },
              {
                value: 25,
                label: '烧烤丸类',
              }
            ]
        },
        {
          value: 4,
          label: '休闲食品',
          children:
            [
              {
                value: 29,
                label: '饼干糕点',

              },
              {
                value: 30,
                label: '谷物冲调',
              },
              {
                value: 31,
                label: '风味小吃',
              }
            ]
        },
        {
          value: 5,
          label: '美妆个护',
          children:
            [
              {
                value: 35,
                label: '面膜',

              },
              {
                value: 36,
                label: '身体护理',
              },
              {
                value: 37,
                label: '口腔护理',
              }
            ]
        },
        {
          value: 6,
          label: '肉禽蛋品',
          children:
            [
              {
                value: 14,
                label: '牛肉',

              },
              {
                value: 15,
                label: '蛋品',
              },
              {
                value: 16,
                label: '猪肉',
              }
            ]
        },
        {
          value: 7,
          label: '粮油速食',
          children:
            [
              {
                value: 20,
                label: '米面油',

              },
              {
                value: 21,
                label: '方便速食',
              },
              {
                value: 22,
                label: '干货杂粮',
              }
            ]
        },
        {
          value: 8,
          label: '乳品酒饮',
          children:
            [
              {
                value: 26,
                label: '碳酸/汽水',

              },
              {
                value: 27,
                label: '饮用水',
              },
              {
                value: 28,
                label: '葡萄酒',
              }
            ]
        },
        {
          value: 9,
          label: '母婴百货',
          children:
            [
              {
                value: 32,
                label: '宠物食品',

              },
              {
                value: 33,
                label: '卫浴用品',
              },
              {
                value: 34,
                label: '衣物洗护',
              }
            ]
        },
        {
          value: 10,
          label: '厨具水具',
          children:
            [
              {
                value: 38,
                label: '锅具烹饪',

              },
              {
                value: 39,
                label: '厨房小电',
              },
              {
                value: 40,
                label: '口腔护理',
              }
            ]
        },
      ],
      tableData: [],
      total: 10,
      page: 1,
      limit: 10,
      drawer: false,
      drawers: false,
      listobj: {
        ishot: 0,
        istehui: 0,
        newprice: '38.00',
        iscutdownmoney: 0,
        img: 'https://img0.baidu.com/it/u=2439198025,4191496025&fm=253&fmt=auto&app=138&f=JPEG?w=750&h=500',
        isprocure: 0,
        assesscount: "666",
        desc: '"尝鲜装，单果200-400 生鲜水果 健康轻食"',
        proinfoimg: "https://img1.baidu.com/it/u=3033226715,2238019049&fm=253&fmt=auto&app=138&f=JPEG?w=800&h=500",
        isnewpro: 0,
        proname: "京觅 大螃蟹，螃蟹锅你值得拥有",
        oldprice: '88.00',
        gettime: '预计今日送达',
        activity: '"两件7折"',
        shopcarcount: '12',
        // assess: [],
        stock: "888",
        brand: "阳光大闸蟹",
        expdate: '78天',
        producer: '广东',
        specs: '无',
        weight: '67KG',
        unit: '箱',
        parentId: 1,
        das:0
      },
      obnus: {
        nus: ''
      },
      oblik: {
        banners: 'https://img1.baidu.com/it/u=716638254,3920932970&f…20672&fm=253&fmt=auto&app=120&f=JPEG?w=1280&h=800',
        proname: '芹菜',
        unit: '份',
        oldprice: 19.9,
        brand: "芹菜",
        description: "宁夏小香菲",
        expdate: "1个月",
        gettime: "预计今日达",
        iscutdownmoney: 1,
        newprice: 15,
        oldprice: 19.9,
        piId: 1,
        proInfoImg: "https://img1.baidu.com/it/u=4289251256,3386957976&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=400",
        producer: "宁夏固原",
        proname: "芹菜",
        shopcarcount: 10,
        specs: "3kg",
        unit: "份",
        weight: "3.100kg",
      },
      mans: 0
    }
  },
  methods: {
    async axsf(){
      let res = await axios({
        method: 'post',
        url: 'http://8.134.169.207:8000/product-info/addproductInfo',
        data: this.listobj
      })
      console.log(res);
    },
    async ad_pro() {
      let res = await axios({
        method: 'post',
        url: 'http://8.134.169.207:8000/product-info/addproduct',
        data: this.listobj
      })
      console.log(res);
      this.handleChange([0, this.mans])
      this.listobj.das = res.data
      this.drawers = true
    },
    //改变二级商品id添加用
    async handleChange(value) {
      this.options.map(item => {
        item.children.map(item => {
          if (item.value == value[1]) {
            this.obnus.nus = item.label
            this.mans = item.value
          } else {
            return;
          }
        })
      })
      this.listobj.parentId = value[1]
      let res = await axios({
        url: 'http://8.134.169.207:8000/category/querythird?',
        params: { categoryId: value[1] }
      })
      console.log(res);
      this.tableData = res.data.data
    },
    handleCurrentchange(val) {
      this.page = val


    },

    leftedit(item) {
      console.log(item);
      // Object.keys(this.listobj).map(ite=>{
      //  this.listobj[ite] = item[ite]
      // })

    }
  },
  mounted() {
    this.handleChange([0, 11])

  }
}
</script>

<style lang="scss" scoped></style>